package com.test.deencredit.analytics_deencredit.timezone_deencredit

import android.text.TextUtils
import java.util.*

object TimeZoneUtil_deencredit {

    /**
     * 获取当前需要回传数据的地区
     */
    private fun currentTimeZoneSupportCountrys_deencredit(): List<String> {
        val list = mutableListOf<String>()
        val timeZoneId = TimeZone.getDefault().id.toString()
        println("======timeZoneId=$timeZoneId")
        when (timeZoneId) {
            TimeZoHostEnum_deencredit.GHA.timeZoId -> {
                list.add(TimeZoHostEnum_deencredit.GHA.country)
            }
            TimeZoHostEnum_deencredit.FCFA.timeZoId -> {
                list.add(TimeZoHostEnum_deencredit.FCFA.country)
            }
            TimeZoHostEnum_deencredit.KSH.timeZoId -> {
                list.add(TimeZoHostEnum_deencredit.KSH.country)
            }
            TimeZoHostEnum_deencredit.UGX.timeZoId -> {
                list.add(TimeZoHostEnum_deencredit.UGX.country)
            }
            TimeZoHostEnum_deencredit.NAIRA.timeZoId -> {
                list.add(TimeZoHostEnum_deencredit.NAIRA.country)
            }
            TimeZoHostEnum_deencredit.VIETNAM.timeZoId -> {
                list.add(TimeZoHostEnum_deencredit.VIETNAM.country)
            }
        }
        return list
    }

    /**
     *  转换为真正需要上报数据的服务器地址列表
     *
     * @param list 配置的服务器地址
     */
    fun covertToRealTargetServers_deencredit(list: List<String>): List<String> {
        val curTimeZoneSupportCountrys: List<String> = currentTimeZoneSupportCountrys_deencredit()
        val serviceTargetUrlList = list.filter { url ->
            curTimeZoneSupportCountrys.any { country -> url.endsWith(country) }
        }
        val resultTargetUrlList = serviceTargetUrlList.ifEmpty { list }
        return resultTargetUrlList
    }

    fun getTimeZoneID_deencredit():String{
        val result = TimeZone.getDefault().id
        if (TextUtils.isEmpty(result)) return ""
        return result
    }
}